#include<iostream>
#include<stdlib.h>
#include<cstring>
void f(char *str, int n)
{
    int count = 0;
    char last=0;
    for(int i = 0; i < n; i++)
    {
        if(str[i]==last)
        {
            count++;
        }else
        {
            if(count==0)
            {
                last=str[i];
                count++;
                continue;
            }
            if(count!=1)
                std::cout<<count<<last;
            else
                std::cout<<last;
            count=1;
            last=str[i];

        }
    }
    if(count!=1)
        std::cout<<count<<last;
    else
        std::cout<<last;
}
int main(int argc, char *argv[])
{
    int n;
    std::cin>>n;
    for(int i = 0; i < n; i++)
    {
        char str[10001]={0};
        std::cin>>str;
        f(str,strlen(str));
        std::cout<<std::endl;
    }
}
